$(function () {
    $("#jqGrid").Grid({
        url: '../report/load/list',
        colModel: [
            {label: '任务ID', name: 'id', width: 40, key: true},
            {label: '组名称', name: 'groupId', width: 70},
            {label: '报表ID', name: 'tableId', width: 70},
            {label: '表名称', name: 'tableName', width: 70},
            {label: '数据日期 ', name: 'dataDt', width: 50},
            {label: '新旧数据', name: 'newOldFlg', width: 30}
        ]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            id: ''
        },
        dataDt: "",
        newOldFlg: "",
        showList: true,
        title: null,
        load: {},
        ruleValidate: {
            dataDt: [
                {required: true, message: '数据名称不能为空', trigger: 'blur'}
            ]
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },

        runOnce: function (event) {
            var jobIds = getSelectedRows("#jqGrid");
            //alert(jobIds.toString())
            if (jobIds == null) {
                return;
            }
            if (vm.dataDt == "") {
                alert("请输入数据日期！")
                return;
            }
            confirm('确定要立即执行选中的记录？', function () {
                Ajax.request({
                    url: "../report/load/run",
                    params: {
                        "tableId": jobIds.toString(),
                        "dataDt": vm.dataDt,
                        "newOldFlg": vm.newOldFlg
                    },
                    contentType: "application/json",
                    type: 'GET',
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'beanName': vm.q.beanName},
                page: page
            }).trigger("reloadGrid");
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        }
    }
});